#!usr/bin/env python  
# -*- coding:utf-8 _*-
""" 
@author:robot
@file: api13_oauth.py 
@version:
@time: 2022/05/07 
"""
from TapClientCore.T02_tm_api.v2_api.v2_api_base import *


class Api13OauthUrl(V2ApiUrlBase):
    url_oauth = api_joint(V2ApiUrlBase().serve, 'oauth')
    url_oauth_token = api_joint(url_oauth, 'token')


class Api13Oauth(V2ApiBase):
    def get_oauth_token(self, payload):
        self.session.headers.update({'content-type': 'application/x-www-form-urlencoded'})
        response = self.tapclient(
            self.post,
            Api13OauthUrl.url_oauth_token
            + self.access_token,
            data=payload
        )
        self.session.headers.update({'content-type': 'application/json'})
        return response.get('access_token')


if __name__ == '__main__':
    T = Api13Oauth()
    params = {
        'grant_type': 'client_credentials',
        'client_id': '5c0e750b7a5cd42464a5099d',
        'client_secret': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9'
    }
    res = T.get_oauth_token(params)
    print(res)
